﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Travel.Web.wb_advertisement
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                       
        }

        		protected void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txttitle.Text.Trim().Length==0)
			{
				strErr+="标题不能为空！\\n";	
			}
			if(this.txtadnum.Text.Trim().Length==0)
			{
				strErr+="广告位编号不能为空！\\n";	
			}
			if(this.txtpicpath.Src.Trim().Length==0)
			{
				strErr+="图片不能为空！\\n";	
			}
			if(this.txtweburl.Text.Trim().Length==0)
			{
				strErr+="链接地址不能为空！\\n";	
			}
			if(this.txtcost.Text.Trim().Length==0)
			{
				strErr+="价值不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtheight.Text))
			{
				strErr+="高格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtwidth.Text))
			{
				strErr+="宽格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtstarttime.Text))
			{
				strErr+="开始日期格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtendTime.Text))
			{
				strErr+="结束日期格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txttype.Value))
			{
				strErr+="广告形式格式错误！\\n";	
			}
            if (!PageValidate.IsNumber(txtisuse.Value))
			{
				strErr+="是否在用格式错误！\\n";	
			}
            //if(this.txtcomment.Text.Trim().Length==0)
            //{
            //    strErr+="备注不能为空！\\n";	
            //}
            //if(this.txtjs.Text.Trim().Length==0)
            //{
            //    strErr+="JS不能为空！\\n";	
            //}
            //if(!PageValidate.IsDateTime(txtcreated_on.Text))
            //{
            //    strErr+="创建时间格式错误！\\n";	
            //}
            //if(this.txtcreated_by.Text.Trim().Length==0)
            //{
            //    strErr+="创建人不能为空！\\n";	
            //}
            //if(!PageValidate.IsDateTime(txtchanged_on.Text))
            //{
            //    strErr+="最后一次修改时间格式错误！\\n";	
            //}
            //if(this.txtchanged_by.Text.Trim().Length==0)
            //{
            //    strErr+="最后一次修改人不能为空！\\n";	
            //}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
            string id = Guid.NewGuid().ToString("N").ToLower();
			string title=this.txttitle.Text;
			string adnum=this.txtadnum.Text;
			string picpath=this.txtpicpath.Src;
			string weburl=this.txtweburl.Text;
			string cost=this.txtcost.Text;
			int height=int.Parse(this.txtheight.Text);
			int width=int.Parse(this.txtwidth.Text);
			DateTime starttime=DateTime.Parse(this.txtstarttime.Text);
			DateTime endTime=DateTime.Parse(this.txtendTime.Text);
			int type=int.Parse(this.txttype.Value);
            int isuse = int.Parse(this.txtisuse.Value);
			string comment=this.txtcomment.Text;
			string js=this.txtjs.Text;
            DateTime created_on = DateTime.Now;
			string created_by=this.txtcreated_by.Text;
            DateTime changed_on = DateTime.Now;
			string changed_by=this.txtchanged_by.Text;

			Travel.Model.wb_advertisement model=new Travel.Model.wb_advertisement();
			model.id=id;
			model.title=title;
			model.adnum=adnum;
			model.picpath=picpath;
			model.weburl=weburl;
			model.cost=cost;
			model.height=height;
			model.width=width;
			model.starttime=starttime;
			model.endTime=endTime;
			model.type=type;
			model.isuse=isuse;
			model.comment=comment;
			model.js=js;
			model.created_on=created_on;
			model.created_by=created_by;
			model.changed_on=changed_on;
			model.changed_by=changed_by;

			Travel.BLL.wb_advertisement bll=new Travel.BLL.wb_advertisement();
			bll.Add(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","add.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }

        protected void bt_upload_Click(object sender, EventArgs e)
        {
            if (this.uploadImage.FileName == "")
            {
                MessageBox.Show(this, "请选择图片");
            }
            else
            {
                # region 产品图片上传(加水印)
                upload upload = new Maticsoft.Common.upload();
                upload.FileType = "jpg|gif|bmp|jpeg|fla";
                upload.Path = @"\upImage\";
                upload.Sizes = 500;
                string images = "";
                images = upload.SaveAs(Request.Files, images);
                if (images == String.Empty || images == "")
                {
                    // Common.PublicFc.Show(this, "常州云计算提醒您：上传图片失败，请重新添加！");
                    MessageBox.Show(this, "上传图片失败，请重新添加");
                    //Response.Redirect("Product_Add.aspx");
                    return;
                }
                else
                {
                    //string[] array = images.Split('|');
                    //this.Image6.Src = (array.Length - 6 < 0 ? "../images/Nopicture.jpg" : array[array.Length - 5]);
                    //this.Image5.Src = (array.Length - 5 < 0 ? "../images/Nopicture.jpg" : array[array.Length - 4]);
                    //this.Image4.Src = (array.Length - 4 < 0 ? "../images/Nopicture.jpg" : array[array.Length - 3]);
                    //this.Image3.Src = (array.Length - 3 < 0 ? "../images/Nopicture.jpg" : array[array.Length - 2]);
                    //this.Image2.Src = (array.Length - 2 < 0 ? "../images/Nopicture.jpg" : array[array.Length - 1]);
                    this.txtpicpath.Src = images;
                }

                //HttpPostedFile hpf = uploadImage.PostedFile;
                //System.Drawing.Image image = System.Drawing.Image.FromStream(hpf.InputStream, true);
                //string waterName = Server.MapPath("~/watermark.png");
                //LEE.upload.AddImageSignPic(image, upload.saveFilePath, waterName, 5, 100, 6);//图片水印
                //LEE.upload.AddImageSignText(image, upload.saveFilePath,"Lemar drying", 5, 100, "Helvetica", 55);//文字水印
                # endregion

            }
        }
    }
}
